package com.fhz.circle.index.ui.home;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;

import com.fhz.circle.databinding.FragmentHomeBinding;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;
import com.qiniu.android.utils.LogUtil;

import org.json.JSONObject;

import java.io.File;


public class HomeFragment extends Fragment {

    private HomeViewModel homeViewModel;
    private FragmentHomeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);


        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        final TextView textView = binding.textHome;
        homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "haha", Toast.LENGTH_SHORT).show();
//                UploadManager uploadManager = new UploadManager();
//                ///storage/emulated/0/feng.jpg
//                File file = new File("/storage/emulated/0/feng.jpg");
//                uploadManager.put(file, "feng1", "echIJ_Aj01Fyc1UzsHALSEOxHd3rRfGiq63RXrRT:QI4SHJZ6fhm0sxIZki1UaAxe4EI=:eyJzY29wZSI6ImZlbmctYmxvZy1hZG1pbiIsImRlYWRsaW5lIjoxNjM3MDY1Mzc3fQ=="
//                        , new UpCompletionHandler() {
//                            @Override
//                            public void complete(String key, ResponseInfo info, JSONObject response) {
//                                Log.i("key",key);
//                            }
//                        },null);
                }
        });

        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}